<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
    <script src="http://res2.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
    <title>微信支付页面</title>
</head>
<script type="text/javascript">
    var jsapi = JSON.parse('{$jsapi}');
    var oid = '{$oid}';
    var pid = '{$pid}';
    //调用微信JS api 支付
    function jsApiCall() {
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest', jsapi,
            function (res) {
                WeixinJSBridge.log(res.err_msg);
                if (res.err_msg == "get_brand_wcpay_request:ok") {
                    //res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
                    $.ajax({
                        url: '{:url("index/wxpay/uporder")}',
                        type: 'get',
                        data: {
                            oid: oid,
                            pid: pid
                        },
                        success: function (obj) {
                            alert('支付成功' + oid + '微信订单' + pid);
                            return WeixinJSBridge.call('closeWindow');
                        },
                        error: function () {
                            alert('网络错误');
                        }
                    });
                } else if (res.err_msg == 'get_brand_wcpay_request:cancel') {
                    alert('支付过程中用户取消');
                    return WeixinJSBridge.call('closeWindow');
                } else {
                    alert('支付失败');
                    return WeixinJSBridge.call('closeWindow');
                }
            }
        );
    }

    function callpay() {
        if (typeof WeixinJSBridge == "undefined") {
            if (document.addEventListener) {
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            } else if (document.attachEvent) {
                document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        } else {
            jsApiCall();
        }
    }

    callpay();
</script>

<body>
</body>

</html>